home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Sound Editor / Source / SoundHandling.h < prev   
Encoding:
C/C++ Source or Header  |  1995-12-11  |  4.4 KB  |  241 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SoundHandling.h
  3.  
  4.     Contains:    CSounder, CPlayer, and CRecorder classes implementation.
  5.  
  6.     Written by:    Andrey Dolgachev
  7.  
  8.     Copyright:    © 1994,95 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11.  
  12. #ifndef _SOUNDHANDLING_
  13. #define _SOUNDHANDLING_
  14.  
  15. // -- Macintosh Includes --
  16.  
  17. #ifndef    __SOUND__
  18. #include <Sound.h>
  19. #endif
  20.  
  21. #ifndef    __SOUNDINPUT__
  22. #include <SoundInput.h>
  23. #endif
  24.  
  25. //------------------------------------------------------------------------------
  26. // Class Definitions
  27. //------------------------------------------------------------------------------
  28.  
  29. // Superclass for common functionality between recording and playing
  30. class CSounder
  31. {
  32.     public:
  33.     
  34.     CSounder();
  35.     ~CSounder();
  36.     
  37.     ODBoolean            IsInitialized();
  38.     ODBoolean            IsPaused();
  39.     ODBoolean            HasSound();
  40.     
  41.     ODFrame*            GetFrame();
  42.     void                SetFrame(ODFrame* f);
  43.  
  44.     ODHandle            GetSound();    
  45.     void                SetSound(ODHandle d);
  46.     void                DisposeSound();
  47.     
  48.     ODSShort            GetLevel();
  49.     ODULong                GetTime();
  50.  
  51.     virtual ODBoolean    IsCompleted();
  52.     
  53.     protected:
  54.     
  55.     virtual ODBoolean    Initialize();
  56.     virtual ODBoolean    DeInitialize();
  57.     
  58.     // Virtual methods handle time-management at this level
  59.     virtual ODBoolean    Start(ODFrame* frame);
  60.     virtual ODBoolean    Stop();
  61.     virtual ODBoolean    Pause();
  62.     virtual ODBoolean    Resume();
  63.  
  64.     ODBoolean            IsSounding();
  65.  
  66.     // Data members used needed by both superclass and its subclasses
  67.     ODHandle    fSoundHandle;
  68.     ODSShort    fMeterLevel;
  69.     
  70.     private:
  71.     
  72.     // Boolean variables for state information
  73.     ODBoolean    fInitialized;
  74.     ODBoolean    fSounding;
  75.     ODBoolean    fPaused;
  76.     
  77.     // External data objects
  78.     ODFrame*    fFrame;
  79.     
  80.     // Time management variables
  81.     ODULong        fStartSecs;
  82.     ODULong        fCurrentTime;    
  83.     ODULong        fPausedSecs;
  84.     ODULong        fPauseStart;
  85.     ODULong        fPauseEnd;    
  86.  
  87. };
  88.  
  89. // Class for playing sound
  90. class CPlayer : public CSounder
  91. {
  92.     public:
  93.     
  94.     CPlayer();
  95.     ~CPlayer();
  96.     
  97.     virtual ODBoolean    Initialize();
  98.     virtual ODBoolean    DeInitialize();
  99.     
  100.     virtual ODBoolean    Start(ODFrame* frame);
  101.     virtual ODBoolean    Stop();
  102.     virtual ODBoolean    Pause();
  103.     virtual ODBoolean    Resume();
  104.     
  105.     ODBoolean            IsPlaying();
  106.     virtual ODBoolean    IsCompleted();
  107.  
  108.     private:
  109.  
  110.     SndChannelPtr        fSoundChannel;
  111.     ODSLong                fSoundChannelRate;
  112.  
  113. };    
  114.  
  115. // Class for recording sound
  116. class CRecorder : public CSounder
  117. {
  118.     public:
  119.     
  120.     CRecorder();
  121.     ~CRecorder();
  122.     
  123.     virtual ODBoolean    Initialize();
  124.     virtual ODBoolean    DeInitialize();
  125.  
  126.     virtual ODBoolean    Start(ODFrame* frame);
  127.     virtual ODBoolean    Stop();
  128.     virtual ODBoolean    Pause();
  129.     virtual ODBoolean    Resume();
  130.     
  131.     ODSLong                GetMaxTime(ODSLong MaxSize, OSType rQuality);
  132.  
  133.     void                SetQuality(OSType rQuality);
  134.     OSType                GetQuality();
  135.     
  136.     ODBoolean            IsRecording();
  137.     virtual ODBoolean    IsCompleted();
  138.     
  139.     private:
  140.  
  141.     ODSLong             fSoundDevice;
  142.     OSType                fRecordingQuality;
  143.     SPB                    sPar;    
  144. };    
  145.  
  146. //------------------------------------------------------------------------------
  147. // Inline methods
  148. //------------------------------------------------------------------------------
  149.  
  150. //==============================================================================
  151. // CSounder
  152. //==============================================================================
  153.  
  154. inline ODBoolean CSounder::IsInitialized()
  155. {
  156.     return fInitialized; 
  157. }
  158.  
  159. inline ODBoolean CSounder::IsPaused()
  160. {
  161.     return fPaused; 
  162. }
  163.  
  164. inline ODBoolean CSounder::HasSound()
  165. {
  166.     return (fSoundHandle != kODNULL); 
  167. }
  168.  
  169. inline ODFrame* CSounder::GetFrame()
  170. {
  171.     return fFrame; 
  172. }
  173.  
  174. inline void CSounder::SetFrame(ODFrame* f)
  175. {
  176.     fFrame = f; 
  177. }
  178.  
  179. inline ODHandle CSounder::GetSound()
  180. {
  181.     return fSoundHandle; 
  182. }
  183.  
  184. inline void CSounder::SetSound(ODHandle d)
  185. {
  186.     this->DisposeSound();
  187.     fSoundHandle = d; 
  188. }
  189.  
  190. inline ODSShort CSounder::GetLevel()
  191. {
  192.     return fMeterLevel; 
  193. }
  194.  
  195. inline ODULong CSounder::GetTime()
  196. {
  197.     return fCurrentTime; 
  198. }
  199.  
  200. inline ODBoolean CSounder::Initialize()
  201. {
  202.     fInitialized = kODTrue;
  203.     return fInitialized;
  204. }
  205.  
  206. inline ODBoolean CSounder::DeInitialize()
  207. {
  208.     fInitialized = kODFalse;
  209.     return !fInitialized;
  210. }
  211.  
  212. inline ODBoolean CSounder::IsSounding()
  213. {
  214.     return fSounding; 
  215. }
  216.  
  217. //==============================================================================
  218. // CPlayer
  219. //==============================================================================
  220.  
  221. inline ODBoolean CPlayer::IsPlaying()
  222. {
  223.     return CSounder::IsSounding(); 
  224. }
  225.  
  226. //==============================================================================
  227. // CRecorder
  228. //==============================================================================
  229.  
  230. inline ODBoolean CRecorder::IsRecording()
  231. {
  232.     return CSounder::IsSounding(); 
  233. }
  234.  
  235. inline OSType CRecorder::GetQuality()
  236. {
  237.     return fRecordingQuality; 
  238. }
  239.  
  240. #endif
  241.